package com.wanmait.recycle.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wanmait.recycle.pojo.Firsttype;
import com.wanmait.recycle.pojo.Rubbish;
import com.wanmait.recycle.pojo.Secondtype;
import com.wanmait.recycle.service.FirsttypeService;
import com.wanmait.recycle.service.RubbishService;
import com.wanmait.recycle.service.SecondtypeService;

@Controller
@RequestMapping("/manager")
public class RubbishTypeController {
	
	@Resource
	private FirsttypeService firsttypeService;
	@Resource
	private SecondtypeService secondtypeService;
	@Resource
	private RubbishService rubbishService;

	@RequestMapping("rubbishTypeFir/rubbishTypeAdd")
	public void rubbishTypeAdd1(){
		
	}
	
	@RequestMapping("rubbishTypeFir/rubbishTypeAddUpLoad")
	public String rubbishTypeAddUpLoad(Firsttype firsttype){
		firsttypeService.insert(firsttype);
		return "redirect:/manager/rubbishTypeFir/rubbishTypeList";
	}
	
	@RequestMapping("rubbishTypeFir/rubbishTypeReAdd")
	@ResponseBody
	public String rubbishTypeAddUpLoad(Integer id){
		firsttypeService.insertById(id);
		return "redirect:/manager/rubbishTypeFir/rubbishTypeList";
	}
	
	
	@RequestMapping("rubbishTypeFir/rubbishTypeChange")
	public ModelAndView rubbishTypeChange(Integer id){
		ModelAndView mv = new ModelAndView();
		Firsttype firsttypes = firsttypeService.findById(id);
		mv.addObject("firsttypes", firsttypes);
		return mv;
	}
	
	@RequestMapping("rubbishTypeFir/rubbishTypeChangeUpLoad")
	public String rubbishTypeChangeUpLoad(Firsttype firsttype){
		firsttypeService.update(firsttype);
	
		return "redirect:/manager/rubbishTypeFir/rubbishTypeList";
		
	}
	
	@RequestMapping("rubbishTypeFir/rubbishTypeList")
	public ModelAndView rubbishTypeList2(){
		ModelAndView mv = new ModelAndView();
		List<Firsttype> firsttypes = firsttypeService.findAll1();
		mv.addObject("firsttypes", firsttypes);
		
		return mv;
		
	}
	
@RequestMapping("rubbishTypeFir/rubbishTypeDelete")
@ResponseBody
	public String rubbishTypeDelete(Integer id){
		
		firsttypeService.delete(id);
		return "redirect:/manager/firsttype/firsttypeList";
	}
	
	@RequestMapping("rubbishTypeFir/secShow")
	public ModelAndView secShow(Integer id){
		ModelAndView mv = new ModelAndView();
		List<Secondtype> secondtypes = secondtypeService.findAllByFirsttypeId(id);
		Firsttype firsttypes = firsttypeService.findById(id);
		mv.addObject("firsttypes", firsttypes);
		mv.addObject("secondtypes", secondtypes);
		return mv;
	}

	@RequestMapping("rubbishTypeFir/rubShow")
	public ModelAndView rubShow(Integer id){
		ModelAndView mv = new ModelAndView();
		List<Rubbish> rubbishs = rubbishService.findAllBySecondTypeId(id);
		Secondtype secondtypes = secondtypeService.findById(id);
		mv.addObject("rubbishs", rubbishs);
		mv.addObject("secondtypes", secondtypes);
		return mv;
	}
	
	@RequestMapping("rubbishTypeFir/changeSortCount")
	@ResponseBody
	public void changeSortCount(Integer Tid,Integer Tcount,Integer id, Integer count){
		System.out.println(Tid);
		firsttypeService.changeSortCount(Tid,count);
		firsttypeService.changeSortCount(id,Tcount);
	}
	
}










